package com.cn.xiaonuo.slbfinances.members.controller;

import cn.hutool.core.convert.Convert;
import com.cn.xiaonuo.common.entity.BusinessMessage;
import com.cn.xiaonuo.core.annotion.BusinessLog;
import com.cn.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import com.cn.xiaonuo.slbfinances.members.param.SlUserParam;
import com.cn.xiaonuo.slbfinances.members.service.IMemberService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.Map;

@CrossOrigin
@RestController
public class MembersController {

    @Resource
    private IMemberService memberService;

    @ApiOperation(value = "会员管理-搜了宝-->会员工具", notes = "会员管理-搜了宝-->会员工具")
    @PostMapping(value ="/api/members/exchange")
    public BusinessMessage exchange(@RequestBody Map<String, Object> params) {
        Integer type= Convert.toInt(params.get("type"));
        Integer cuserId=Convert.toInt(params.get("cuserId"));
        Integer muserId=Convert.toInt(params.get("muserId"));
        BigDecimal money=Convert.toBigDecimal(params.get("money"));
        Integer operaUserId= Convert.toInt(params.get("operaUserId"));
        String userName= Convert.toStr(params.get("userName"));
        return memberService.exchange(type, cuserId, muserId, money, operaUserId, userName);
    }

    @ApiOperation(value = "会员管理--搜了宝-->上下级记录--列表页", notes = "会员管理--搜了宝-->上下级记录--列表页")
    @PostMapping(value ="/api/members/queryRelation")
    public BusinessMessage queryRelation(@RequestBody Map<String, Object> params) {
        Integer pageNo= Convert.toInt(params.get("pageNo"));
        Integer pageSize=Convert.toInt(params.get("pageSize"));
        String userId=Convert.toStr(params.get("userId"));
        String phone=Convert.toStr(params.get("phone"));
        return memberService.queryRelation(pageNo, pageSize, userId, phone);
    }
    @PostMapping("/api/members/queryLowerLevel")
    public BusinessMessage queryLowerLevel(@RequestBody Map<String, Object> params) {
        Integer pageNo= Convert.toInt(params.get("pageNo"));
        Integer pageSize=Convert.toInt(params.get("pageSize"));
        Integer userId=Convert.toInt(params.get("userId"));
       return memberService.queryLowerLevel(pageNo,pageSize,userId);

    }

    @PostMapping("/api/members/membersPage")
    @ApiOperation(value = "会员管理列表", notes = "会员管理列表")
    @BusinessLog(title = "会员管理列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public BusinessMessage membersPage(SlUserParam slUserParam) {
        return memberService.membersPage(slUserParam);
    }

    @PostMapping("/api/members/membersDetail")
    @ApiOperation(value = "会员管理详情", notes = "会员管理详情")
    @BusinessLog(title = "会员管理详情", opType = LogAnnotionOpTypeEnum.QUERY)
    public BusinessMessage membersDetail(SlUserParam slUserParam) {
        return memberService.membersDetail(slUserParam);
    }

    @ApiOperation(value = "会员信息导出", notes = "会员信息导出")
    @GetMapping(value = "/api/members/listExport")
    public void listExport(HttpServletResponse response, SlUserParam slUserParam) {
        memberService.listExport(response,slUserParam);
    }
}
